/*
 ID: brodyzt1
 PROG: dualpal
 LANG: C++
*/

#include <iostream>
#include <string>
#include <fstream>
#include <ostream>
#include <sstream>
#include <math.h>

using namespace std;

double Reverse(double number)
{
    double reverseNumber;
    double remainder;
    double ten = 10;
    while(number)
    {
        //extract the last digit from the number
        remainder = modf(number, &ten);
        
        //build the reverseNumber digit by digit
        reverseNumber = (reverseNumber * 10) + remainder;
        
        //exclude the last digit from the number
        //ready for the next evaluation
        number = number / 10;    
    }
    return number;
}

string toString (double num)
{
    stringstream temp;
    temp.precision(30);
    temp << num;
    string tempString;
    temp >> tempString;
    return tempString;
}

double reversedInt (double origNumber)
{
    string tempString = toString(origNumber);
    string newString = tempString;
    stringstream tempStream;
    tempStream.precision(30);
    for (int i = 0; i < tempString.length(); i++) {
        tempStream << newString[newString.length() - (1+i)];
    }
    double reversedNum;
    tempStream >> reversedNum;
    return reversedNum;
}

double convertBases (int origNumber, int newBase)
{
    double newNumber = 0;
    int index = 0;
    int quotient = origNumber;
    while (quotient != 0) {
        newNumber += (quotient % newBase) * pow(10, index);
        quotient = (quotient - (quotient % newBase)) / newBase;
        index ++;
    }
    return newNumber;
}

bool isPalendrome (double origNumber)
{
    bool isPalendrome = true;
    if (toString(origNumber)[0] == '0') {
        isPalendrome = false;
    }
    if (!(origNumber == reversedInt(origNumber))) {
        isPalendrome = false;
    }
    return isPalendrome;
}

int main(int argc, const char * argv[])
{
    cout.precision(30);
    ifstream input;
    input.open("dualpal.in");
    int N, S;
    input >> N >> S;
    
    ofstream output;
    output.open("dualpal.out");
    int numFound = 0;
    
    int index = S + 1;
    while (numFound < N) {
        int numTrue = 0;
        for (int j = 2; j <= 10; j++) {
            if (isPalendrome(convertBases(index, j))) {
                numTrue ++;
            }
            
        }
        if (numTrue > 1) {
            output << index << "\n";
            numFound ++;
        }
        index ++;
    }
    
    input.close();
    output.close();
    return 0;
}

